package com.haotunet.app.goldtreasure.adapter;

import java.util.List;
import com.haotunet.app.goldtreasure.R;
import com.haotunet.app.goldtreasure.activity.ExchangeRecordDetailAct;
import com.haotunet.app.goldtreasure.model.ExchangeRecord;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class ExchangeRecordAdapter extends HolderAdapter<ExchangeRecord, ExchangeRecordAdapter.ViewHolder> {

	public ExchangeRecordAdapter(Context context, List<ExchangeRecord> mlist) {
		super(context, mlist);
	}

	public static class ViewHolder {
		TextView tvExchangeQuantity;
		TextView tvStoreAddress;
		TextView tvOrderNO;
		TextView tvTradeStatus;
		TextView tvExchangeTime;
	}

	@Override
	public View buildConvertView(LayoutInflater layoutInflater, ExchangeRecord t, int position) {
		return inflate(R.layout.item_exchange_record);
	}

	@Override
	public ViewHolder buildHolder(View convertView, ExchangeRecord t, int position) {
		ViewHolder holder = new ViewHolder();
		holder.tvExchangeQuantity = (TextView) convertView.findViewById(R.id.txt_exchange_quantity);
		holder.tvExchangeTime = (TextView) convertView.findViewById(R.id.exchange_time);
		holder.tvOrderNO = (TextView) convertView.findViewById(R.id.exchange_order_no);
		holder.tvStoreAddress = (TextView) convertView.findViewById(R.id.txt_store_address);
		holder.tvTradeStatus = (TextView) convertView.findViewById(R.id.txt_trade_status);
		return holder;
	}

	@Override
	public void bindViewDatas(View convertView, ViewHolder holder, ExchangeRecord exchangeRecord, int position) {
		holder.tvExchangeQuantity.setText(exchangeRecord.getQuantity());
		holder.tvExchangeTime.setText(exchangeRecord.getCreateTime());
		final String orderNo = exchangeRecord.getOrderNo();
		holder.tvOrderNO.setText(orderNo);
		holder.tvStoreAddress.setText(exchangeRecord.getShopName());
		holder.tvTradeStatus.setText(exchangeRecord.getStatusText());
		convertView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(context, ExchangeRecordDetailAct.class);
				intent.putExtra("orderNo", orderNo);
				context.startActivity(intent);
			}
		});

	}
}
